home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
handle20.zip
/
FILES3X.ASM
< prev
next >
Wrap
Assembly Source File
|
1987-07-17
|
18KB
|
397 lines
;****************************************************************************
; file: files3x.asm by: Steven M. Gibson, Irvine, CA created: 06/06/87
;****************************************************************************
;
; * * * PUBLIC DOMAIN COPYRIGHT RELEASE NOTICE * * *
;
; THIS PROGRAM, IN BOTH SOURCE CODE AND OBJECT FORM, HAS BEEN EXPLICITLY
; PLACED INTO THE PUBLIC DOMAIN BY ITS SOLE AUTHOR AND OWNER, STEVEN GIBSON,
; OF IRVINE, CA. IT MAY THEREFORE BE FREELY REPRODUCED, EXCHANGED, UPLOADED
; AND DOWNLOADED. HOWEVER THE AUTHOR REQUESTS THAT THIS NOTICE OF RELEASE
; AND ORIGIN OF AUTHORSHIP BE LEFT INTACT AND THAT THIS PROGRAM OR ITS DIRECT
; DERRIVATIVES, IF ANY, *NOT* BE SOLD FOR PROFIT. ALSO, PLEASE KEEP THE
; ENTIRE SET OF FILES TOGETHER AS ONE PACKAGE. ----> Thanks
;
;****************************************************************************
;
; About The Program: FILES.COM (source code file: files3x.asm)
;
; "FILES.COM" is a small resident (TSR) program which overcomes a major
; glitch in the way IBM has implemented DOS 3.30. Specifically, it handles
; the requirements of explicitly ASKING DOS for additional handles and
; keeping a block of RAM available for DOS when this request is made.
; Any program can now have up to 256 files open when under 3.0-3.2 (counting
; the standard pre-opened default files) if the command "FILES" is issued
; first. This program also has the interesting ability to spontaneously
; remove itself ("Un-TSR") from memory after doing its job.
;
; If you wish to suppress the message FILES delivers when it is run, simply
; put anything after the command, (like: "files shhh") and it won't say a
; word as it goes resident. Otherwise it makes a short (non-commercial)
; statement of its intent as it terminates.
;
; NOTE: This program *ONLY* makes sense when under versions 3.0 thru 3.2
; of DOS, and will refuse to run under any earlier DOS versions.
; Use the other DOS 3.3 version of FILES.COM (source: files3x.asm)
;****************************************************************************
;
; About These SOURCE CODE FILES:
;
; This source code file, and the companion OPENER.ASM source code file, were
; written to be instructional, clear, and a bit tutorial in nature. As such
; they have been commented more heavily than normal self-communication
; would normally dictate. I hope you will find them interesting, useful,
; and not overly verbose. They are also examples of a general coding style
; I've found to endure quite well. Adopt it if you like it.
;
; NOTE: These files were created using the incredible file editor: BRIEF
;
;****************************************************************************
;
; To make a COM file from this ASM source code:
;
; masm files3x, files3x; <--- assemble the .asm to .obj
; link files3x; <--- link the .obj to .exe
; exe2bin files3x files3x.com <--- convert .exe to .com
; del files3x.obj <--- delete the intermediate debris
; del files3x.exe
;
;****************************************************************************
;----------------------------------------------------------------------------
; E Q U A T E S
;----------------------------------------------------------------------------
CR equ 0Dh
LF equ 0Ah
COM_TERMINATE equ 20h ; .COM program termination
DOS_FUNC equ 21h ; Interrupt to call DOS
DOS_PRINTSTRING equ 09h ; Dos Sub-Function Defs
DOS_SET_VECTOR equ 25h
DOS_VERSION_NUMBER equ 30h ; " "
DOS_STAY_RESIDENT equ 31h
DOS_GET_VECTOR equ 35h
DOS_CREATE equ 3Ch ; " "
DOS_OPEN equ 3DH
DOS_ALLOC equ 48H
DOS_DEALLOC equ 49H
DOS_SETBLOCK equ 4AH
DOS_EXEC equ 4BH
DOS_GET_PSP equ 62h
SET_HANDLE_COUNT equ 67h
NEW_MAX_HANDLES equ 256 ; assuming 256 handle params
MINIMUM_VERSION equ 3 * 256 + 00 ; later than ver: "3"."00"
MAXIMUM_VERSION equ 3 * 256 + 30 ; earlier than ver: "3"."30"
HANDLE_CLOSED_FLAG equ 0FFh
;----------------------------------------------------------------------------
; M A C R O S
;----------------------------------------------------------------------------
zero MACRO p1 ; this little macro is just too
xor p1,p1 ; handy to be without. Since it
ENDM ; "cleanly" zeros any register.
;----------------------------------------------------------------------------
; C O D E S E G M E N T
;----------------------------------------------------------------------------
CODESEG SEGMENT BYTE PUBLIC
ASSUME CS:CODESEG, DS:CODESEG
ORG 02Ch ; pointer to this program's environ
Environment LABEL WORD
ORG 032h ; maximum process file handles
MaxHandleCount LABEL WORD
ORG 034h ; offset of the handle pointer table
HandleTableOff LABEL WORD
ORG 036h ; maximum process file handles
HandleTableSeg LABEL WORD
ORG 080h
ParameterCount LABEL BYTE ; count of the command-line params
ORG 100h ; .com programs execute from 0100h
ComStart: jmp TransientCode ; jump past the resident portion
;****************************************************************************
; RESIDENT CODE PORTION BEGINS HERE
;****************************************************************************
OldDosInt dd ? ; original int 21 vector pointer
TriggerEnable db 0 ; non-zero after enabling EXEC call
HoleSegment dw ? ; segment location of the "hole"
;----------------------------------------------------------------------------
; NOTE TO THE READER: The following "resident portion" of the TSR will make
; *MUCH* more sense if you have FIRST read the "transient portion" below. I
; suggest that you jump ahead and read that first, then come back to here....
;----------------------------------------------------------------------------
Int21Intercept:
;----------------------------------------------------------------------------
; The transient portion of this program pointed DOS' calling Interrupt 21
; here before terminating itself. Therefore we receive control every time
; anyone does an Int21h call to DOS. (Until we've fulfilled our mission)
;----------------------------------------------------------------------------
cmp ah, DOS_EXEC ; is DOS starting a program?
jne NotEnablingCall ; nope, so skip the enabling
mov cs:TriggerEnable, -1 ; yes!, so we simply enable
jmp Int21Continue ; and resume Int21 monitoring
NotEnablingCall:cmp ah, DOS_OPEN ; was the call an open handle?
je SeeIfReady ; yep, are we ready to go?
cmp ah, DOS_CREATE ; was it a create handle?
je SeeIfReady ; yep ....
AbortIntercept: jmp Int21Continue ; (too far for a cond. jmp)
SeeIfReady: cmp cs:TriggerEnable, 0 ; have we been enabled by EXEC
je AbortIntercept ; nope, so ignore the OPEN
cmp cs:HoleSegment, 0 ; did we already do our thing?
je AbortIntercept ; yep, so don't do it again!
push ax ; save the caller's calling
push bx ; parameters on his own stack
push cx
push si
push di
push ds
push es
;----------------------------------------------------------------------------
; Free up the memory block, located at "HoleSegment", which was previously
; allocated by (and therefore owned by) our transient portion
;----------------------------------------------------------------------------
mov es, cs:HoleSegment ; get the segment number
mov cs:HoleSegment, 0 ; zero it so we don't again
mov ah, DOS_DEALLOC
int DOS_FUNC ; and release that ram block
;----------------------------------------------------------------------------
; And now we reallocate it (or maybe some other free chunk lying around)
; to the CURRENTLY running process's identity. This way the current
; process "owns" the block so it too will be released when he terminates.
;----------------------------------------------------------------------------
mov bx, (NEW_MAX_HANDLES+15)/16 ; use paragraphs
mov ah, DOS_ALLOC
int DOS_FUNC
mov es, ax ; and hold onto the block's segment
;-----------------------------------------------------